
/// MLSDEFORMER source code
/// by Alvaro Cuno, LCG-COPPE-UFRJ
/// bugs? email-me: alvaroecp@gmail.com
/// November, 2007

#ifndef __ANIMATOR_H__
#define __ANIMATOR_H__

#include "../typedefs.h"
#include "mesh.h"
#include "meshWithSkeleton.h"
#include "motion.h"

class Animator {
   
public:
   /// Constructors
   Animator(): mesh(0), motion(0), framescursor(-1) {}
   Animator(MeshWithSkeleton *me, Motion *m);
   
   void next(); // the next frame
   void prev(); // the previous frame
   void last(); // the last frames
   void first(); // the first frame
   void frame(int f); // the frame number f
   
private:
   
   /// Initalizes some values
   void setting();
   
   /// Deforms the mesh following the skeleton deformation
   void project_deformation_on_mesh_std_dualquat();
   
   /// Computes the rotation around bone i
   Vector3 getRotationAroundBoneRep(unsigned int i);
   
   /// Gets the rotation ...
   void getRotationRep(unsigned int i);
   
   /// Given a u rotation representation rotates the vector v
   void computeRotation(const Number v[]);

   /// Recovers the initial geometry of the skeleted-mesh
   void recoverInitData();

private:
   
   vector<Point3>             ipositions; // initial vertex positions
   vector<Vector3>            inormals; // initial vertex normal
   
   vector<Vector3>            ubones; // rotation representation for bones
   vector<Vector3>            tvectors0; // translation applied to joints of bones
   vector<Vector3>            tvectors1; // translation applied to joints of bones
   vector<Number>             tscalar0; // 
   vector<Number>             tscalar1; // 
   
   std::vector<Vector3>       tlvectors0; // translation applied to joints of bones
   std::vector<Vector3>       tlvectors1; // translation applied to joints of bones
   
   
   Number                     u[3];     //< u value 
   Number                     vxu[3], rv[3], factor;     //< a factor value
   
   vector<vector<Number> >    old_angle;
   vector<int>                turns;
   bool comprotaround;
   
public:
   
   int                        framescursor; // the frames cursor
   
   MeshWithSkeleton           *mesh;
   Motion                     *motion;
};

#endif
